<%@ page import="java.util.*" %>
 <%@ page import="com.ionglobal.db.*" %>
 <%@ page import="com.ionglobal.lib.*" %>
<%@ page contentType="text/html;charset=GBK" %>
 
 <%@ include file="../init_include.jsp" %>
 <%
	int pageid = 0;
	int pagerows = 10;
	int totalrows = 0;
	int totalpages = 1;
	String orderby = "id";
	String orderby2 = "asc";
	String temp = "";
	String sql = "";
	
	temp=request.getParameter("pageid");
	if( temp != null && temp.trim().length() > 0)
		pageid=Integer.parseInt(temp);

	temp=request.getParameter("orderby");
	if( temp != null && temp.trim().length() > 0)
		orderby=temp.trim();

	temp=request.getParameter("orderby2");
	if( temp != null && temp.trim().length() > 0)
		orderby2=temp.trim();
	
	temp=request.getParameter("pagerows");
	if( temp != null && temp.trim().length() > 0){
		pagerows = Integer.parseInt(temp);
		if( pagerows <=0 ) pagerows = 10;
		//session.setAttribute("pagerows",temp);
	}

	String name = "";
	String code = "";
	String ename = "";
	String parentid = "";
	String phone = "";
	String fax = "";
	String email = "";
	String leader = "";
	String descript = "";
	String layer = "";
	int id=0;

	name = request.getParameter("name");
	code = request.getParameter("code");
	ename = request.getParameter("ename");
	parentid = request.getParameter("parentid");
	phone = request.getParameter("phone");
	fax = request.getParameter("fax");
	email = request.getParameter("email");
	leader = request.getParameter("leader");
	descript = request.getParameter("descript");
	layer = request.getParameter("layer");
	if(request.getParameter("id")!=null)
		id=Integer.parseInt(request.getParameter("id")); 	

 	if(id!=0) {
 		
 		sql = "update sys_depart set ";
		sql = sql + "name='"+ dbi.fixSql(name) +"', ";
		sql = sql + "code='"+ dbi.fixSql(code) +"', ";
		//sql = sql + "ename='"+ dbi.fixSql(ename) +"', ";
		sql = sql + "parentid=" + parentid +", ";
		sql = sql + "phone='"+ dbi.fixSql(phone) +"', ";
		sql = sql + "fax='"+ dbi.fixSql(fax) +"', ";
		sql = sql + "email='"+ dbi.fixSql(email) +"', ";
		sql = sql + "leader='"+ dbi.fixSql(leader) +"', ";
		sql = sql + "descript = "+ dbi.setLargeTextField( descript) + ", ";
		//sql = sql + "descript='"+ dbi.fixSql(descript) +"', ";
		sql = sql + "layer=" + layer +"" + " where id=" + id;
		dbi.execute( sql );
		dbi.updateLargeTextField( "sys_depart"," where id="+ id, "descript",descript );	
		
 	} else {
 	
		long newid = SequenceManager.getNextValue( dbi,"sys_depart_seq");	
 		sql = "insert into sys_depart( id, name,code,parentid,phone,fax,email,leader,descript,layer) values( ";
 		//sql = "insert into sys_depart( name,parentid,phone,fax,email,leader,descript,layer) values( ";
		sql = sql + newid +", ";
		sql = sql + "'"+ dbi.fixSql(name) +"', ";
		sql = sql + "'"+ dbi.fixSql(code) +"', ";
		//sql = sql + "'"+ dbi.fixSql(ename) +"', ";
		sql = sql + parentid +", ";
		sql = sql + "'"+ dbi.fixSql(phone) +"', ";
		sql = sql + "'"+ dbi.fixSql(fax) +"', ";
		sql = sql + "'"+ dbi.fixSql(email) +"', ";
		sql = sql + "'"+ dbi.fixSql(leader) +"', ";
		sql = sql +  dbi.setLargeTextField( descript) + ", ";
		//sql = sql + "'"+ dbi.fixSql(descript) +"', ";
		sql = sql + layer +")";
 
		dbi.execute( sql );
		dbi.updateLargeTextField( "sys_depart"," where id="+ newid, "descript",descript );	
	} 	
 %>
<script Language="JavaScript" src="../script/Ion_Show.js"></script> 
<script language="javascript">
	closewindow(0);
</script>	
<%@ include file="../init_free.jsp" %>  